/**
 *  Class OtrDecoderOptions is part of the project OtrMediaManager
    Copyright (C) 2014  Gerrit Eichel

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package otrmediamanager.otr;

import java.io.File;
import java.io.FileNotFoundException;

/**
 * This class represents available OTR decoder options. 
 */
public class OtrDecoderOptions {
	/** The input file option identifier. */
	private static String INPUT_FILE_OPTION = " -i ";
	/** The output folder option identifier. */
	private static String OUTPUT_FOLDER_OPTION = " -o ";
	/** The email option identifier. */
	private static String EMAIL_OPTION = " -e ";
	/** The password option identifier. */
	private static String PASSWORD_OPTION = " -p ";
	/** The overwrite option identifier.*/
	private static String OVERWRITE_OPTION = " -f ";
	/** The version option identifier. */
//	private static String VERSION_OPTION = "-v";

	/** The OTR user credentials used for login.*/
	private OtrUser _otrUserCredentials = null;
	/** The OTR source file to be decoded.*/
	private File _otrSourceFile = null;
	/** The OTR decoder output folder to store decoded files.*/
	private File _otrOutputFolder = null;
	/** The enable overwrite option flag. */
	private boolean _enableOverwiteOptionFlag = false;

	/**
	 * Initializes a new OtrDecoderOptions instance.
	 * @param otrUserCredentials The OTR user credentials.
	 * @param otrSourceFile The OTR source file to be decoded.
	 * @param otrOutputFolder The OTR output folder to store decoded files.
	 * @throws FileNotFoundException If source file is not found, or output folder is not existing.
	 */
	public OtrDecoderOptions(OtrUser otrUserCredentials, File otrSourceFile, File otrOutputFolder) throws FileNotFoundException {
		this.setOtrUserCredentials(otrUserCredentials);
		this.setOtrSourceFile(otrSourceFile);
		this.setOtrOutputFolder(otrOutputFolder);
	}
	
	/**
	 * Returns OTR user credentials used for login.
	 * @return The OTR user credentials.
	 */
	public OtrUser getOtrUserCredentials() {
		return this._otrUserCredentials;
	}
	/**
	 * Sets OTR user credentials used for login.
	 * @param otrUserCredentials The OTR user credentials.
	 */
	private void setOtrUserCredentials(OtrUser otrUserCredentials) {
		if (otrUserCredentials == null) {
			throw new java.lang.IllegalArgumentException("Property <OtrUserCredentials> is not initialized!");
		}
		this._otrUserCredentials = otrUserCredentials;
	}
	/**
	 * Returns OTR source file to be decoded.
	 * @return The OTR source file to be used.
	 */
	public File getOtrSourceFile() {
		return this._otrSourceFile;
	}
	/**
	 * Sets OTR source file to be decoded.
	 * @param otrSourceFile The OTR source file to be used.
	 * @throws FileNotFoundException Is thrown if OTR source is not found.
	 */
	private void setOtrSourceFile(File otrSourceFile) throws FileNotFoundException {
		if (otrSourceFile == null) {
			throw new java.lang.IllegalArgumentException("Property <OtrSourceFile> is not initialized!");
		}
		if (!otrSourceFile.exists()) {
			throw new FileNotFoundException("Property <OtrSourceFile> not found!");
		}
		if (!otrSourceFile.isFile()) {
			throw new java.lang.IllegalArgumentException("Property <OtrSourceFile> is not a file!");
		}
		this._otrSourceFile = otrSourceFile;
	}
	/**
	 * Returns the OTR decoder output folder to store decoded files.
	 * @return The OTR decoder output folder.
	 */
	public File getOtrOutputFolder() {
		return this._otrOutputFolder;
	}
	/**
	 * Sets OTR decoder output folder to store decoded files in.
	 * @param otrOutputFolder The OTR decoder output folder.
	 * @throws FileNotFoundException If output folder is not found.
	 */
	private void setOtrOutputFolder(File otrOutputFolder) throws FileNotFoundException {
		if (otrOutputFolder == null) {
			throw new java.lang.IllegalArgumentException("Property <OtrOutputFolder> is not initialized!");
		}
		if (!otrOutputFolder.exists()) {
			throw new FileNotFoundException("Property <OtrOutputFolder> not found!");
		}
		if (!otrOutputFolder.isDirectory()) {
			throw new java.lang.IllegalArgumentException("Property <OtrOutputFolder> is not a folder!");
		}
		this._otrOutputFolder = otrOutputFolder;
	}
	/**
	 * Returns state of overwrite enable flag.
	 * @return The flag state.
	 */
	public boolean getEnableOverwriteOption() {
		return this._enableOverwiteOptionFlag;
	}
	/** Enables or disables overwrite option.*/
	public void setEnableOverwriteOption(boolean enableOverwite) {
		this._enableOverwiteOptionFlag = enableOverwite;
	}
	/**
	 * Composes OTR decoder command line options.
	 * @return The composed OTR decoder command line options.
	 */
	public String getOtrDecoderCommandLineOptions() {
		String otrDecoderCommandLineOptions = INPUT_FILE_OPTION + this.getOtrSourceFile().getAbsolutePath()
				+ OUTPUT_FOLDER_OPTION + this.getOtrOutputFolder().getAbsolutePath()
				+ EMAIL_OPTION + this.getOtrUserCredentials().getUsername()
				+ PASSWORD_OPTION + this.getOtrUserCredentials().getUserPassword();
		if (this._enableOverwiteOptionFlag) {
			otrDecoderCommandLineOptions = otrDecoderCommandLineOptions + OVERWRITE_OPTION;
		}
		return otrDecoderCommandLineOptions;
	}
}
